script_enemy_main{

let angle=0;
let bulletdir=rand(0,360);
let curve=2.5;

let damagerate=10;
let frame=0;
let time=0;
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;

let SEshots7=("script\SoundEffects\shots7.wav");
let SEdeath=("script\SoundEffects\enemydeath1.wav");

SetAngle(GetArgument);
SetSpeed(4);

@Initialize{
	LoadSE("script\SoundEffects\shots7.wav");
	LoadSE("script\SoundEffects\enemydeath1.wav");

	SetScore(100);
	SetLife(20);
	SetInvincibility(60);
	SetDamageRate(10,10);
}
	
@MainLoop{

SetCollisionA(GetX,GetY,16);
SetCollisionB(GetX,GetY,16);

if(GetX<=minx-100 || GetX>=maxx+100 || GetY<=miny-100 || GetY>=maxy+100 && time>=60){ VanishEnemy; }

if(time>=0){
	let shotx=0;
	SetShotColor(255,255,255);
	CreateShotA(shotx,GetX,GetY,0);
	SetShotDataA(shotx,0,0,GetAngle,0,0,0,37);
	SetShotKillTime(shotx,1);
	FireShot(shotx);
}

if(time<60 && GetSpeed>0){ SetSpeed(GetSpeed-0.06); }

if(time>=60 && time<240){
	SetSpeed(GetSpeed+0.025);
	angle=atan2(GetPlayerY-GetY,GetPlayerX-GetX);

	if(angle>360){ angle=angle-360; }
	if(angle<0){ angle=angle+360; }
	if(GetAngle>360){ SetAngle(GetAngle-360); }
	if(GetAngle<0){ SetAngle(GetAngle+360); }

	let difference=GetAngle-angle;
	if(difference<0){ difference+=360; }
	if(difference>360){ difference-=360; }
	if(difference>180){ SetAngle(GetAngle+curve); }
	if(difference<180){ SetAngle(GetAngle-curve); }
	
if(curve>0){ curve-=0.02; }
if(time%10==0){ PlaySE(SEshots7); }
}

if(time%5==0 && time>=3){
	let shotx=0;
	CreateShotA(shotx,GetX,GetY,10);
	SetShotDataA(shotx,0,0,GetAngle+90*cos(bulletdir),0,0,0,54);
	SetShotDataA(shotx,75,0,NULL,0,0.01,1.5,55);
	FireShot(shotx);
}

bulletdir+=8;


time++;
frame++;
}

@DrawLoop{
}

@Finalize{
	if(BeVanished==false){ DeleteEnemyShot(CHILD); PlaySE(SEdeath); SetCommonData("FamiliarDestroyed",1); }
}

}